package com.maimang.platform.controller.system;

import com.maimang.platform.base.BaseController;
import com.maimang.platform.common.config.Global;
import com.maimang.platform.common.entity.SysDept;
import com.maimang.platform.common.entity.SysDeptTree;
import com.maimang.platform.common.entity.SysMenu;
import com.maimang.platform.common.entity.SysUser;
import com.maimang.platform.common.service.SysDeptService;
import com.maimang.platform.common.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Rocky
 * @version 1.0.0
 * @类名 SysIndexController
 * @描述 <br>系统首页</br>
 * @日期 2019-03-24
 * @email jintaozhao@qq.com
 */
@Controller
public class SysIndexController extends BaseController {
	@Autowired
	private SysMenuService menuService;

	@Autowired
	private SysDeptService sysDeptService;

	// 系统首页
	@GetMapping("/index")
	public String index(ModelMap modelMap, HttpServletResponse response) throws IOException {
		// 取身份信息
		SysUser user = getSysUser();
		if (user == null) {
			return "login";
		}
		// 根据用户id取出菜单
		List<SysMenu> menus = menuService.selectMenusByUser(user);
		modelMap.put("menus", menus);
		modelMap.put("user", user);
		modelMap.put("copyrightYear", Global.getCopyrightYear());
		return "index";
		// return "win10";
	}

	// 系统介绍
	@GetMapping("/system/main")
	public String main(ModelMap modelMap) {
		modelMap.put("version", Global.getVersion());
		return "main";
	}
}
